<div class="col-lg-3">

  <h3>User moderation:</h3> 

  <p>Moderators and admins have the ability to ban users if they post inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email <a href="mailto:moderators@<%= request.host %>">moderators@<%= request.host %></a>. If we all work together, we can keep spam to a minimum. Thanks for helping out!</p>

  <hr />

</div>

<div class="col-lg-9">

  <h3>Moderate users</h3>

  <table class="table">
  <tr><th>Username</th><th>Posts</th><th>Created</th><th>Email</th><th>Action</th></tr>
  <% @users.each do |user| %>
  <tr id="u<%= user.id %>">
    <td><a href="/profile/<%= user.name %>"><%= user.name %></a></td>
    <td><%= Node.where(uid: user.id).size %></td>
    <td><%= time_ago_in_words(user.created_at) %></td>
    <td><%= user.mail %></td>
    <td><div class="btn-toolbar" style="margin:0;">
      <div class="btn-group">
        <% if user.status == 0 %>
          <a class="btn btn-outline-secondary btn-lg btn-success unban" data-remote="true" href="/unban/<%= user.id %>"><i class="fa fa-ok-circle fa fa-white"></i> Unban</a>
        <% else %>
          <%= link_to "/ban/"+user.id.to_s, :confirm => 'Are you sure?', :remote => true, :class => "btn btn-lg btn-danger ban" do %>
            <i class="fa fa-circle-ban"></i> Ban
          <% end %>
        <% end %>
      </div>
      <script>
        $('#u<%= user.id %> .ban').bind('ajax:success', function(e){
          $('#u<%= user.id %>').fadeOut()
          $('#uban<%= user.id %>').fadeIn()
        });
        $('#u<%= user.id %> .unban').bind('ajax:success', function(e){
          $('#u<%= user.id %>').hide()
          $('#uunb<%= user.id %>').fadeIn()
        });
      </script>
    </div></td>
  </tr>
  <tr style="display:none;" id="uunb<%= user.id %>">
    <td><a href='/profile/<%= user.name %>'>User unbanned</a>.</td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr style="display:none;" id="uban<%= user.id %>">
    <td><a href='/profile/<%= user.name %>'>User banned</a>.</td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <% end %>
  </table>

</div>
